package cn.iocoder.yudao.module.pplan.dal.mysql.recipe;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.pplan.controller.admin.recipe.vo.RecipePageReqVO;
import cn.iocoder.yudao.module.pplan.controller.app.recipe.vo.AppRecipePageReqVO;
import cn.iocoder.yudao.module.pplan.dal.dataobject.recipe.RecipeDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;

/**
 * 生产计划-餐谱数据管理 Mapper
 *
 * @author yisl
 */
@Mapper
public interface RecipeMapper extends BaseMapperX<RecipeDO> {

    default PageResult<RecipeDO> selectPage(RecipePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RecipeDO>()
                .eqIfPresent(RecipeDO::getRecipeCode, reqVO.getRecipeCode())
                .likeIfPresent(RecipeDO::getRecipeName, reqVO.getRecipeName())
                .eqIfPresent(RecipeDO::getAirlineId, reqVO.getAirlineId())
                .eqIfPresent(RecipeDO::getAirlineType, reqVO.getAirlineType())
                .eqIfPresent(RecipeDO::getCabinClass, reqVO.getCabinClass())
                .eqIfPresent(RecipeDO::getMealService, reqVO.getMealService())
                .eqIfPresent(RecipeDO::getMealSet, reqVO.getMealSet())
                .eqIfPresent(RecipeDO::getIsActive, reqVO.getIsActive())
                .betweenIfPresent(RecipeDO::getEndDate, reqVO.getExpireDate())
                .eqIfPresent(RecipeDO::getRemarks, reqVO.getRemarks())
                .betweenIfPresent(RecipeDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(RecipeDO::getId));
    }

    default PageResult<RecipeDO> appSelectPage(AppRecipePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RecipeDO>()
                .likeIfPresent(RecipeDO::getRecipeName, reqVO.getRecipeName())
                .eqIfPresent(RecipeDO::getAirlineId, reqVO.getAirlineId())
                .eqIfPresent(RecipeDO::getAirlineType, reqVO.getAirlineType())
                .eqIfPresent(RecipeDO::getCabinClass, reqVO.getCabinClass())
                .eqIfPresent(RecipeDO::getMealService, reqVO.getMealService())
                .orderByDesc(RecipeDO::getId));
    }

    // 需要将其他航空公司、航线类型、舱位等级、餐食类别相同的状态改为停用
    default int updateRecipeisActiveByFE(RecipeDO recipeDO, Boolean isActive) {
        return update(new LambdaUpdateWrapper<RecipeDO>()
                .eq(RecipeDO::getAirlineId, recipeDO.getAirlineId())
                .eq(RecipeDO::getAirlineType, recipeDO.getAirlineType())
                .eq(RecipeDO::getCabinClass, recipeDO.getCabinClass())
                .eq(RecipeDO::getMealService, recipeDO.getMealService())
                .set(RecipeDO::getIsActive, isActive));
    }

}